

import java.math.BigDecimal;
import java.util.Random;

import any.Any;
import any.functor.interfaces.NumberAnyAggregateFunction;

import static any.functor.Functions.asSum;

public class AnyPerformance {

	private static final int REPETITION = 10;
	private static final int SIZE = 360000;
	
	public static void main(String[] args) {
		int[] values = new int[SIZE];
        Random rand = new Random();
        for (int i = 0; i < values.length; i++) {
        	values[i] = rand.nextInt();
        }
        
        long startTime = System.currentTimeMillis();
        
        Any valuesAny = Any.create.any(values);
        for (int i = 0; i < REPETITION; i++) {
        	valuesAny.give(asSum());
        }
        System.out.println("Time any.give: " + (System.currentTimeMillis() - startTime) / 1000.0);
        
        startTime = System.currentTimeMillis();
        valuesAny = Any.create.any(values);
        NumberAnyAggregateFunction asSum = asSum();
        for (int i = 0; i < REPETITION; i++) {
        	valuesAny.give(asSum);
        }
        System.out.println("Time any.give (function inlined): " + (System.currentTimeMillis() - startTime) / 1000.0);
        
        /*        
        startTime = System.currentTimeMillis();
        for (int i = 0; i < REPETITION; i++) {
        	ImmutableAny.util.give(values, asSum);
        }
        System.out.println("Time Any.util.give: " + (System.currentTimeMillis() - startTime) / 1000.0);
        */
        
        startTime = System.currentTimeMillis();
        for (int i = 0; i < REPETITION; i++) {
        	BigDecimal sum = BigDecimal.ZERO;
        	for (int j = 0; j < values.length; j++) {
        		sum = sum.add(BigDecimal.valueOf(values[j]));
        	}
        }
        
        System.out.println("Time native: " + (System.currentTimeMillis() - startTime) / 1000.0);
	}

}
